﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoiceAI;
using VoiceAI.VoiceResponse;
using Windows.ApplicationModel.Core;
using Windows.Data.Json;
using XiaoweiV2;
using XiaoweiV2.ResponseDataTypes;

namespace XiaoweiVoiceAI.ResponseCreators
{
    internal static class OpenAppResponseCreatorForSettingPage2
    {
        private class OpenAppResponse : IOpenAppResponseData
        {

            public VoiceAI.ResponseType ResponseType => VoiceAI.ResponseType.OpenApp;

            public ErrorCode ErrorCode => ErrorCode.NoError;

            public string RequestText { get; set; }

            public string ResponseText { get; set; }

            public string TTSUrl { get; set; }

            public bool RestoreInHistory => true;

            public object DataContext { get; set; }

            public string AppName { get; set; } = "";

            public AppType AppType => AppType.SettingPage;
        }
        public static IResponseData CreateResponseData(XiaoweiVoiceAI xiaoweiVoiceAI, ResponseParam param)
        {
            JsonObject jsonObject = JsonObject.Parse(param.ResponseData);
            JsonArray jsonArray = jsonObject.GetNamedArray("slots");
            Dictionary<string, string> Data = new Dictionary<string, string>();
            foreach (var item in jsonArray)
            {
                Data[item.GetObject().GetNamedString("key")] = item.GetObject().GetNamedString("value");
            }
            if (!Data.ContainsKey("page")) Data["page"] = "";
            OpenAppResponse openAppResponse = new OpenAppResponse();
            openAppResponse.RequestText = param.RequestText;
            openAppResponse.ResponseText = "正在打开设置页面";
            openAppResponse.TTSUrl = xiaoweiVoiceAI.TextToVoice("正在打开设置页面");
            openAppResponse.AppName = Data["page"];
            return openAppResponse;
        }
    }
}
